"""
头皮策略基础类
"""
from abc import ABC, abstractmethod
from typing import Optional, Dict, Tuple
import pandas as pd


class BaseStrategy(ABC):
    """
    策略基础类
    所有策略都应继承此类
    """

    def __init__(self, config: Dict):
        """初始化策略"""
        self.config = config
        self.signals = {}

    @abstractmethod
    def generate_signal(self, df: pd.DataFrame) -> Tuple[str, float]:
        """
        生成交易信号

        Args:
            df: K线DataFrame (必须包含技术指标)

        Returns:
            (信号: buy/sell/hold, 信心度: 0-1)
        """
        pass

    def validate_data(self, df: pd.DataFrame) -> bool:
        """验证数据有效性"""
        if df is None or len(df) < 20:
            return False

        required_columns = ['open', 'high', 'low', 'close', 'volume']
        return all(col in df.columns for col in required_columns)
